package com.cooge.jiexi;

import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Locale;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class WASU {

	public static void main(String[] args) throws Exception {
		
		
		String link = "http://www.wasu.cn/Play/show/id/1483597";
		
		int start = link.lastIndexOf("/");
		
		link = link.substring(start).replaceAll("[^0-9]", "");
		
		String playurl = "http://clientapi.wasu.cn/Phone/vodinfo/id/"+1483562;
		System.out.println(playurl);
		String html = NetUtil.getHtml(playurl);
		JSONObject json = JSONObject.parseObject(html);
		 playurl = json.getString("playurl");
		 URL localURL= new URL(playurl);
		
		 JSONArray  vods = json.getJSONArray("vods");
		 
		 for(int i = 0;i<vods.size();i++){
			 JSONObject playjson =  vods.getJSONObject(i);
			 
			String url =  playjson.getString("url");
			 if(url.contains("apkvod-cnc")||url.contains("mobilevod")){
				 
				 System.out.println(getPlayUrl(new URL(playjson.getString("url")),playurl));
			 }else{
				 System.out.println(url);
			 }
		 }
		
		
		

	}
	
	
	public static String getPlayUrl(URL localURL,String url) throws Exception{
		System.out.println(localURL.getHost());
		String paramString2 = "liveWASU1234@#&*";
		String str3 = getDateCompleteStr(System.currentTimeMillis());
		URL url_ = new URL(url);
		 String str4 = url.substring(url.indexOf(url_.getHost()) + url_.getHost().length());
		 paramString2 = paramString2 + str3 + str4;
		 String playurl = "http://"+localURL.getHost() + "/" + str3 + "/" + NetUtil.md5(paramString2)+str4;
		return playurl;
	}
	
	 public static String getDateCompleteStr(long paramLong)
	  {
	    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("", Locale.SIMPLIFIED_CHINESE);
	    localSimpleDateFormat.applyPattern("yyyyMMddHHmm");
	    return localSimpleDateFormat.format(Long.valueOf(paramLong));
	  }

}
